//
//  ClubViewController.m
//  SugarPile
//
//  Created by Charlie. on 16/1/18.
//  Copyright © 2016年 www.lanou39.蓝鸥科技. All rights reserved.
//

#import "ClubViewController.h"
#import "LCPrefixHeader.pch"
#import "ClubTableViewCell.h"
#import "ClubModel.h"
#import "TaobaoWebViewController.h"
@interface ClubViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *clubTableView; /**< club */
@property (nonatomic, retain) NSMutableArray *dataArr; /**< 数据 */
@property (nonatomic, assign) CGFloat h; /**<自适应高度*/
@end

@implementation ClubViewController

-(void)dealloc
{
    [_clubTableView release];
    [_dataArr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // TabelView
    [self createTableView];
    // 数据处理
    [self dataHandle];
}
- (void)createTableView
{
    self.clubTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _clubTableView.delegate = self;
    _clubTableView.dataSource = self;
    [self.view addSubview:_clubTableView];
    [_clubTableView registerClass:[ClubTableViewCell class] forCellReuseIdentifier:@"cell"];
//    [_clubTableView release];
}
- (void)dataHandle
{
    NSString *str = @"http://203.80.144.212/napi/topic/article/list/?platform_version=4.4.4&device_platform=HM%2B2A&__dtac=%257B%257D&screen_width=720&screen_height=1280&__domain=www.duitang.com&app_version=69&start=0&platform_name=Android&locale=zh&limit=0&type=by_banner&app_code=nayutas";
    NSString *urlStr = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:str]];
    [LCAFNetWorking GETWithURL:urlStr completion:^(id result) {
        
        self.dataArr = [ClubModel modelHanderWithArray:result[@"data"][@"object_list"]];
        [self.clubTableView reloadData];
        
    }];
}
#pragma mark - 协议方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    NSLog(@"%ld", _dataArr.count);
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ClubTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    ClubModel *m = _dataArr[indexPath.row];
    cell.commentLabel.text = m.visit_count.stringValue;
    cell.contentLabel.text =m.title;
    cell.userNameLabel.text = m.cover_desc;


    [cell.pathView sd_setImageWithURL:[NSURL URLWithString:m.photo_path]];
    
    
    cell.pathView.frame = CGRectMake(0, 0, 0, 0);
//    cell.userNameLabel.text =[[m.username stringByAppendingString:@" · "]stringByAppendingString:m.name];

    
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    ClubModel *m = _dataArr[indexPath.row];
    TaobaoWebViewController *tao = [[[TaobaoWebViewController alloc] init] autorelease];
    tao.ID = m.userid;
    [self.navigationController pushViewController:tao animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
